package com.aos.erp.common.dao.handler;

import com.aos.erp.common.utils.id.IdMakerUtils;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

/**  自定义填充公共 name 字段  */
public class AosMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Object idType = getFieldValByName("id", metaObject);
        if(idType!=null) {
            long id=(long)metaObject.getValue("id");
            //如果没设置过值，则补充设置id
            if(id==0) {
                String className = metaObject.getOriginalObject().getClass().getSimpleName();
                setFieldValByName("id", IdMakerUtils.getId(className), metaObject);
            }
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {

    }
}
